import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import p001 from "./p001";
import p002 from "./p002";
import p003 from "./p003";
import p004 from "./p004";
import p005 from "./p005";
export default async function a001(fd: IFeidaoAiBrowserComponent) {
	// todo
	const page = fd.data.params['page-no'] as string;
	let no = 1;
	if (page) {
		no = parseInt(page, 10);
	}

	const qymc = fd.data.node.querySelector<HTMLInputElement>('[data-id="qymc"]').value;
	const qyfr = fd.data.node.querySelector<HTMLInputElement>('[data-id="qyfr"]').value;
	const res = await nodejs<{ res: Array<{}>, t: number }>('company-factory/zj-000001/s001',
		{
			company_name: { $like: '%' + qymc + '%' },
			corporate: { $like: '%' + qyfr + '%' },
			page_no: no
		});

	if (res.res.length > 0) {
		render(fd, res.res, p001, 'p001', "inner");
		render(fd, res.t, p004, 'p004', "inner");
	} else {
		render(fd, '', p003, 'p001', "inner");
		render(fd, '', p005, 'p004', "inner");
	}
}
